function [A, dAdpar] = T2Magnitude( par, echoes)

% computes the magnitude M with given parameters and inversion times
% echoes = [n x 1] inversion times
% par = the 2 element parametervector [A, R2]'
%
% The datamodel is given by
% M = A*exp(-echoes*R2).
%
% Created by Henk Smit, EMC, 01-2011 based on the work by Dirk Poot,
% University of Antwerp, 13-8-2007

if size(par,1) ~= 2 %HENK
    error('incorrect parameter vector');
end;
numtr = size(par,2);
numgr = size(echoes,1);

A = zeros(numgr,numtr);
A_ex = zeros(numgr,numtr);
for k=1:numtr
    A_ex(:,k) = exp(-echoes(:,1)*par(2,k)); %HENK matrix with all results 
    A(:,k) = par(1,k) * A_ex(:,k);     %HENK
end;

if nargout>1
    dAdpar=[A_ex(:) -repmat(echoes,numtr,1).* A(:)]; %HENK 
end;
